package com.twang.stock.design.impl;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.design.IndexDataTask;
import com.twang.stock.dto.IndexedInfo;
import com.twang.stock.entity.HkShMoneyInOut;
import com.twang.stock.redis.RedisUtil;
import com.twang.stock.task.QueryBanKuaiAndDaPan;
import com.twang.stock.utils.date.HolidayCopy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.concurrent.CountDownLatch;

/**
 * 北上资金
 */
@Slf4j
@Service
public class DfcfBeiShangZiJingTask extends IndexedInfo implements IndexDataTask {
    public static String cache_key="DfcfBeiShangZiJingTask";

    public static String CACHE_KEY_BEI_SHANG_AMT="CACHE_KEY_BEI_SHANG_AMT:%s";


    @Autowired
    private RedisUtil redisUtil;


    @Override
    public void execute(ModelAndView modelAndView, CountDownLatch latch) throws Exception {
        try {
            Object obj = redisUtil.get(cache_key);
            HkShMoneyInOut hkShMoneyInOut;
            if (null == obj) {
                hkShMoneyInOut = QueryBanKuaiAndDaPan.getHGTInOut();
            } else {
                hkShMoneyInOut = JSONObject.parseObject(obj.toString(), HkShMoneyInOut.class);
            }
            modelAndView.addObject("bszj", hkShMoneyInOut);
            log.info("沪港通,北上={} ", JSONObject.toJSONString(hkShMoneyInOut));
            //
            setBeiShangZiJing(JSONObject.toJSONString(hkShMoneyInOut));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            log.info("北上资金 执行完成，当前剩余条数:{}", latch.getCount());
            latch.countDown();
        }
    }
}
